package com.example.freshmenapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import org.w3c.dom.ls.LSOutput;

public class MainActivity extends AppCompatActivity
        implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 将UI中的id为btn_login的按钮找到，并赋值为btnLogin变量
        Button btnLogin = findViewById(R.id.btn_login);
        Button btnLogin2 = findViewById(R.id.btn_login2);

        btnLogin.setOnClickListener(this);
        btnLogin2.setOnClickListener(this);
/*
        class MyOnClickListener implements View.OnClickListener{

            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this,
                        "点击事件发生了", Toast.LENGTH_SHORT).show();

            }
        }
        // 创建MyOnClickListener类型的对象作为btnLogin对象的点击事件监听器
        btnLogin.setOnClickListener(new MyOnClickListener());
*/
       /* btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "点击事件发生了", Toast.LENGTH_SHORT).show();

            }
        });*/
    }

    @Override
    public void onClick(View v) {
        Toast.makeText(this, "点击事件发生了", Toast.LENGTH_SHORT).show();
        int id = v.getId();
        switch (id) {
            case R.id.btn_login:
                Toast.makeText(this, "1号", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_login2:
                Toast.makeText(this, "2号", Toast.LENGTH_SHORT).show();
                break;

        }
    }
}